/*
 * $Id: $
 */
package org.rcgwt.client.ui.grid.internal;

import org.rcgwt.client.ui.grid.internal.model.IHeaderModel;

/**
 * 
 * @author Olivier Oeuillot (latest modification by $Author: $)
 * @version $Revision: $ $Date: $
 */
public class HeaderModelDelta extends DefaultModelElementDelta<IHeaderModel> {

    private static final int SCROLL_POSITION_CHANGED = 0x0010;

    private int oldScrollPosition;

    private int newScrollPosition;

    protected HeaderModelDelta(IHeaderModel headerModel) {
        super(headerModel);
    }

    public void performScrollPositionChanged(int oldScrollPosition,
            int newScrollPosition) {

        if (hasScrollPositionChanged() == false) {
            updateKind(SCROLL_POSITION_CHANGED);
            this.oldScrollPosition = oldScrollPosition;
        }

        this.newScrollPosition = newScrollPosition;
    }

    public int getOldScrollPosition() {
        return oldScrollPosition;
    }

    public int getNewScrollPosition() {
        return newScrollPosition;
    }

    public boolean hasScrollPositionChanged() {
        return (getKind() & SCROLL_POSITION_CHANGED) > 0;
    }

    @Override
    protected String toValuesString() {
        return super.toValuesString() + " oldScrollPosition="
                + oldScrollPosition + " newScrollPosition=" + newScrollPosition;
    }

}
